#include "include/Program.h"

namespace Tool
{

struct Program::ProgramPrivater
{
    std::string m_path = "";
    Variant m_archive;
    std::mutex m_mutex;
};


Program::Program()
    : m_privater(std::make_unique<ProgramPrivater>())
{

}

Program::~Program()
{

}

const std::string &Program::Path() const
{
    return m_privater->m_path;
}

bool Program::Load(const std::string &path, VariantSerializeType type)
{
    if(path.empty())
    {
        return false;
    }
    m_privater->m_path = path;
    return m_privater->m_archive.DeserializeFromFile(path, type);
}

bool Program::Save(const std::string &path, VariantSerializeType type)
{
    m_privater->m_path = path;
    return m_privater->m_archive.SerializeToFile(path, type);
}

Variant &Program::GetVariant()
{
    return m_privater->m_archive;
}

Variant &Program::operator [](const std::string &key)
{
    return m_privater->m_archive[key];
}

Variant &Program::operator [](const char *key)
{
    return m_privater->m_archive[key];
}
}
